<template>
	<div>
		<el-dialog title="添加" width="600px" class="icon-dialog" :visible.sync="show" @open="open" :before-close="closeForm" append-to-body>
			<el-form :size="size" ref="form" :model="form" :rules="rules" :label-width="$store.getters.device == 'mobile'?'90px':'16%'">
				<el-row >
					<el-col :span="24">
						<el-form-item label="姓名" prop="name">
							<el-input  v-model="form.name" autoComplete="off" clearable  placeholder="请输入姓名"></el-input>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row >
					<el-col :span="24">
						<el-form-item label="昵称" prop="nick_name">
							<el-input  v-model="form.nick_name" autoComplete="off" clearable  placeholder="请输入昵称"></el-input>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row >
					<el-col :span="24">
						<el-form-item label="头像" prop="avatar">
							<Upload v-if="show" size="small"      file_type="image" :image.sync="form.avatar"></Upload>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row >
					<el-col :span="24">
						<el-form-item label="手机号" prop="mobile">
							<el-input  v-model="form.mobile" autoComplete="off" clearable  placeholder="请输入手机号"></el-input>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row >
					<el-col :span="24">
						<el-form-item label="openid" prop="openid">
							<el-input  v-model="form.openid" autoComplete="off" clearable  placeholder="请输入openid"></el-input>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row >
					<el-col :span="24">
						<el-form-item label="union_id" prop="union_id">
							<el-input  v-model="form.union_id" autoComplete="off" clearable  placeholder="请输入union_id"></el-input>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row >
					<el-col :span="24">
						<el-form-item label="密码" prop="passwd">
							<el-input  show-password autoComplete="off" v-model="form.passwd"  clearable placeholder="请输入密码"/>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row >
					<el-col :span="24">
						<el-form-item label="调用次数" prop="num">
							<el-input  v-model="form.num" autoComplete="off" clearable  placeholder="请输入调用次数"></el-input>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row >
					<el-col :span="24">
						<el-form-item label="邀请人" prop="share_id">
							<select-page v-if="show" url="/admin/Member/getShare_id" :selectval.sync="form.share_id"></select-page>
						</el-form-item>
					</el-col>
				</el-row>
			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button :size="size" :loading="loading" type="primary" @click="submit" >
					<span v-if="!loading">确 定</span>
					<span v-else>提 交 中...</span>
				</el-button>
				<el-button :size="size" @click="closeForm">取 消</el-button>
			</div>
		</el-dialog>
	</div>
</template>

<script>
import SelectPage from '@/components/common/SelectPage.vue'
import Upload from '@/components/common/ImagesUpload.vue'
export default {
	components:{
		SelectPage,
		Upload,
	},
	props: {
		show: {
			type: Boolean,
			default: false
		},
		size: {
			type: String,
			default: 'small'
		},
	},
	data(){
		return {
			form: {
				name:'',
				nick_name:'',
				avatar:'',
				mobile:'',
				openid:'',
				union_id:'',
				passwd:'',
				create_time:'',
				ip:'',
				num:20,
				share_id:'',
			},
			loading:false,
			rules: {
				mobile:[
					{pattern:/^1[3456789]\d{9}$/, message: '手机号格式错误'}
				],
				num:[
					{pattern:/^[0-9]*$/, message: '调用次数格式错误'}
				],
			}
		}
	},
	methods: {
		open(){
		},
		submit(){
			this.$refs['form'].validate(valid => {
				if(valid) {
					this.loading = true
					this.$axios.post('/admin/Member/add',this.form).then(res => {
						if(res.data.status == 200){
							this.$message({message: res.data.msg, type: 'success'})
							this.$emit('refesh_list')
							this.closeForm()
						}else{
							this.loading = false
							this.$message.error(res.data.msg)
						}
					}).catch(()=>{
						this.loading = false
					})
				}
			})
		},
		closeForm(){
			this.$emit('update:show', false)
			this.loading = false
			if (this.$refs['form']!==undefined) {
				this.$refs['form'].resetFields()
			}
		},
	}
}
</script>

<style  lang="scss">
@import '@/assets/scss/common.scss'
</style>
